package com.yh.controller;

import com.opensymphony.xwork2.ModelDriven;
import com.yh.entity.Users;
import com.yh.services.IUsersService;
import com.yh.services.impl.UsersServiceImpl;
import com.yh.util.BaseAction;

import lombok.Data;

@Data
public class UsersAction extends BaseAction implements ModelDriven {
    private Users users;
    private String veryCode;
    IUsersService ius = new UsersServiceImpl();

    @Override
    public Object getModel() {
        if (users == null) {
            users = new Users();
        }
        return users;
    }

    public String register() {

        Users use = new Users(
                users.getName(),
                users.getPassword(),
                users.getTelephone(),
                users.getUserName()
        );
        ius.usersReg(use);

        return "reg";
    }

    public String login() {
        String yzm = YzmAction.generatorVCode;
        System.out.println(veryCode);
        System.out.println(yzm);
        Users use = new Users(
                users.getName(),
                users.getPassword()
        );
        int falg = 0; //判断验证码是否正确
        if (yzm.equalsIgnoreCase(veryCode)) {
            falg = 1;
        }
        Users u = ius.usersLog(use);
        if (u != null && falg==1) {
            return SUCCESS;
        }
        return ERROR;
    }

}
